home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / shopdrop.swf / scripts / __Packages / Player.as < prev    next >
Text File  |  2007-09-27  |  9KB  |  305 lines

  1. class Player extends MovieClip
  2. {
  3.    var nPackages = 0;
  4.    var stackMax = 7;
  5.    var nCrap = 3;
  6.    var cCrap = 0;
  7.    var packHorizMove = 20;
  8.    var stackM = 0;
  9.    var mdir = 0;
  10.    var kickMultiplier = 7;
  11.    var sFrame = "walk";
  12.    var stackLength = 7;
  13.    var nBalance = 10;
  14.    var cBalance = 0;
  15.    var bBalance = false;
  16.    function Player()
  17.    {
  18.       super();
  19.       var _loc4_ = 500;
  20.       this.swapDepths(_loc4_);
  21.       _global.nPlayerY = this._y;
  22.       Player.floor = this.mcFloor._y - this.packageHolder._y;
  23.       this.mcConstLeft = this._parent.mcConstraintLeft;
  24.       this.mcConstRight = this._parent.mcConstraintRight;
  25.       this.pOrigin = new smashing.Point(this._x,this._y);
  26.    }
  27.    function updateWalk(nElapsed)
  28.    {
  29.       var _loc9_ = this.aStack.length;
  30.       this._x = _global.mcRoot._xmouse;
  31.       if(this._x < this.mcConstLeft._x)
  32.       {
  33.          this._x = this.mcConstLeft._x;
  34.       }
  35.       if(this._x > this.mcConstRight._x)
  36.       {
  37.          this._x = this.mcConstRight._x;
  38.       }
  39.       var _loc4_ = undefined;
  40.       var _loc14_ = this.aPackages.length;
  41.       var _loc5_ = undefined;
  42.       _loc4_ = 0;
  43.       while(_loc4_ < _loc14_)
  44.       {
  45.          _loc5_ = this.aPackages[_loc4_];
  46.          if(_loc5_ != null)
  47.          {
  48.             if(_loc5_.lastY >= this._y && _loc5_._y <= this._y)
  49.             {
  50.                if(this.a.hitTest(_loc5_))
  51.                {
  52.                   if(_loc5_.bGrabbed == false)
  53.                   {
  54.                      switch(_loc5_.nType)
  55.                      {
  56.                         case GrabPackage.NORMAL:
  57.                            _loc5_.bGrabbed = true;
  58.                            this.addPackage();
  59.                            _loc5_.a.play();
  60.                            _loc9_ = _loc9_ + 1;
  61.                            break;
  62.                         case GrabPackage.BONUS:
  63.                            this.oWorld.onBonus();
  64.                            _loc5_.a.play();
  65.                            break;
  66.                         case GrabPackage.BALANCE:
  67.                            this.balance();
  68.                            _loc5_.a.play();
  69.                      }
  70.                   }
  71.                }
  72.             }
  73.          }
  74.          _loc4_ = _loc4_ + 1;
  75.       }
  76.       if(_loc9_ > 1)
  77.       {
  78.          var _loc22_ = nElapsed * smashing.Phys.gr * (_loc9_ * 1.7) * this.oWorld.level;
  79.          this.vStack.y += _loc22_;
  80.          var _loc10_ = new smashing.Point(this.vStack.x - this._x,this.vStack.y - this._y);
  81.          var _loc18_ = StackPackage.packageHeight * this.stackLength;
  82.          this.stackM -= smashing.Phys.drag(this.stackM,nElapsed);
  83.          if(this.stackM < 1)
  84.          {
  85.             this.stackM = 0;
  86.          }
  87.          if(this.bBalance == false)
  88.          {
  89.             _loc10_.x += this.stackM * nElapsed * this.mdir;
  90.             _loc10_.length = _loc18_;
  91.          }
  92.          else
  93.          {
  94.             _loc10_.x = 0;
  95.             _loc10_.y = -1;
  96.             _loc10_.length = _loc18_;
  97.             this.cBalance += nElapsed;
  98.             _global.mcRoot.mcMenu.mcBalance.display.mcPercent.gotoAndStop(Math.ceil(this.cBalance));
  99.             if(this.cBalance >= this.nBalance)
  100.             {
  101.                this.unBalance();
  102.             }
  103.          }
  104.          this.vStack.x = this._x + _loc10_.x;
  105.          this.vStack.y = this._y + _loc10_.y;
  106.          var _loc17_ = undefined;
  107.          if(this.vStack.x > this.mcConstRight._x)
  108.          {
  109.             _loc17_ = Math.abs(this.mcConstRight._x - this._x) * this.kickMultiplier;
  110.             this.vStack.x = this.mcConstRight._x;
  111.             this.stackM += _loc17_;
  112.             this.mdir = -1;
  113.          }
  114.          else if(this.vStack.x < this.mcConstLeft._x)
  115.          {
  116.             _loc17_ = Math.abs(this.mcConstLeft._x - this._x) * this.kickMultiplier;
  117.             this.vStack.x = this.mcConstLeft._x;
  118.             this.stackM += _loc17_;
  119.             this.mdir = 1;
  120.          }
  121.          var _loc19_ = smashing.Phys.pUp.dot(_loc10_) / _loc18_;
  122.          if(_loc19_ >= 1)
  123.          {
  124.             _loc19_ = 1;
  125.          }
  126.          var _loc20_ = Math.acos(_loc19_);
  127.          var _loc13_ = smashing.Phys.pHoriz.dot(_loc10_);
  128.          if(_loc13_ == 0)
  129.          {
  130.             _loc13_ = 1;
  131.          }
  132.          _loc13_ /= Math.abs(_loc13_);
  133.          _loc20_ *= _loc13_;
  134.          var _loc12_ = _loc20_ / _loc9_;
  135.          var _loc15_ = _loc12_ / 3.141592653589793 * 180;
  136.          var _loc8_ = undefined;
  137.          var _loc7_ = undefined;
  138.          var _loc6_ = new smashing.Point(0,0);
  139.          _loc4_ = 0;
  140.          while(_loc4_ < _loc9_)
  141.          {
  142.             _loc5_ = this.aStack[_loc4_];
  143.             _loc7_ = _loc12_ * _loc4_;
  144.             _loc5_._x = _loc6_.x;
  145.             _loc5_._y = _loc6_.y;
  146.             _loc5_._rotation = _loc15_ * _loc4_;
  147.             _loc8_ = new smashing.Point(Math.sin(_loc7_),- Math.cos(_loc7_));
  148.             _loc8_.length = StackPackage.packageHeight;
  149.             _loc6_.addPointMe(_loc8_);
  150.             _loc4_ = _loc4_ + 1;
  151.          }
  152.          var _loc16_ = Math.abs(_loc20_ / 3.141592653589793);
  153.          if(_loc16_ >= 0.5)
  154.          {
  155.             this.collapse();
  156.          }
  157.          var _loc11_ = _global.mcRoot.mcXHair;
  158.          _loc11_._visible = true;
  159.          _loc11_._x = this.vStack.x;
  160.          _loc11_._y = this.vStack.y;
  161.          if(this.bBalance == false)
  162.          {
  163.             _loc11_._visible = true;
  164.             _loc11_.a.gotoAndStop(Math.ceil(_loc16_ / 0.5 * 3));
  165.          }
  166.          else
  167.          {
  168.             _loc11_._visible = false;
  169.          }
  170.          _loc11_._rotation = (- _loc16_) * 180 * _loc13_;
  171.       }
  172.       else
  173.       {
  174.          _global.mcRoot.mcXHair._visible = false;
  175.       }
  176.       this.nPackages = this.aStack.length;
  177.       _root.nDebug1 = this.stackM;
  178.    }
  179.    function updateCollapse(nElapsed)
  180.    {
  181.       _global.mcRoot.mcXHair._visible = false;
  182.       this.a.change();
  183.       this.cCrap += nElapsed;
  184.       var _loc4_ = Math.floor((1 - this.cCrap / this.nCrap) * 100);
  185.       var _loc3_ = 0;
  186.       while(_loc3_ < this.aStack.length)
  187.       {
  188.          this.aStack[_loc3_].update(nElapsed);
  189.          this.aStack[_loc3_]._alpha = _loc4_;
  190.          _loc3_ = _loc3_ + 1;
  191.       }
  192.       if(this.cCrap >= this.nCrap)
  193.       {
  194.          this.oWorld.onUncollapse();
  195.       }
  196.    }
  197.    function reset()
  198.    {
  199.       this.stackM = 0;
  200.       this.sFrame = "walk";
  201.       this.update = this.updateWalk;
  202.       this.removeAllPackages();
  203.       this.addPackage(true);
  204.       this.cCrap = 0;
  205.       this.nPackages = this.aStack.length;
  206.       this._x = this.pOrigin.x;
  207.       this._y = this.pOrigin.y;
  208.       _global.mcRoot.mcXHair._visible = false;
  209.    }
  210.    function startWalk()
  211.    {
  212.       this.a.clothes.pants.play();
  213.    }
  214.    function stopWalk()
  215.    {
  216.       this.a.clothes.pants.stop();
  217.    }
  218.    function addPackage(bReset)
  219.    {
  220.       if(bReset != true)
  221.       {
  222.          _global.oSound.playSnd("pickUp");
  223.       }
  224.       var _loc3_ = this.aStack.length;
  225.       if(_loc3_ < this.stackMax)
  226.       {
  227.          var _loc4_ = this.packageHolder.attachMovie("mcObjects","clip" + _loc3_,_loc3_);
  228.          this.aStack.push(_loc4_);
  229.          if(this.aStack.length == 2)
  230.          {
  231.             this.vStack = new smashing.Point(this._x,(- StackPackage.packageHeight) * this.stackLength + this._y);
  232.             this.stackM = 15;
  233.             this.mdir = 1;
  234.          }
  235.          else if(this.aStack.length == 1)
  236.          {
  237.             _loc4_.nObject = 3;
  238.          }
  239.       }
  240.       else
  241.       {
  242.          this.oWorld.onMaxStack();
  243.       }
  244.       if(_loc3_ == this.stackMax - 1)
  245.       {
  246.          this.oPackages.toGiftCards();
  247.          var _loc5_ = _global.mcRoot.mcPopups;
  248.          _loc5_._visible = true;
  249.          _loc5_.gotoAndPlay("maxStack");
  250.          _global.mcRoot.mcMusic.fadeToTwo();
  251.       }
  252.    }
  253.    function removeAllPackages()
  254.    {
  255.       var _loc2_ = 0;
  256.       while(_loc2_ < this.aStack.length)
  257.       {
  258.          this.aStack[_loc2_].removeMovieClip();
  259.          _loc2_ = _loc2_ + 1;
  260.       }
  261.       this.aStack = [];
  262.    }
  263.    function collapse()
  264.    {
  265.       var _loc6_ = this.aStack.length;
  266.       var _loc5_ = new smashing.Point(this.vStack.x - this._x,this.vStack.y - this._y);
  267.       var _loc4_ = smashing.Phys.pHoriz.dot(_loc5_);
  268.       if(_loc4_ == 0)
  269.       {
  270.          _loc4_ = 1;
  271.       }
  272.       _loc4_ /= Math.abs(_loc4_);
  273.       var _loc3_ = 0;
  274.       while(_loc3_ < this.aStack.length)
  275.       {
  276.          this.aStack[_loc3_].m = new smashing.Point(this.packHorizMove * _loc3_ * _loc4_,0);
  277.          _loc3_ = _loc3_ + 1;
  278.       }
  279.       this.update = this.updateCollapse;
  280.       this.oWorld.onCollapse();
  281.       this.sFrame = "ohcrap";
  282.       this.a.change();
  283.       this.oPackages.toPackages();
  284.       _global.mcRoot.mcXHair._visible = false;
  285.    }
  286.    function balance()
  287.    {
  288.       _global.mcRoot.mcMenu.mcBalance.gotoAndPlay(2);
  289.       _global.oSound.playSnd("pickUp");
  290.       this.cBalance = 0;
  291.       this.bBalance = true;
  292.    }
  293.    function unBalance()
  294.    {
  295.       _global.mcRoot.mcMenu.mcBalance.gotoAndStop(1);
  296.       this.bBalance = false;
  297.       this.stackM = 15;
  298.       this.mdir = 1;
  299.    }
  300.    function onEnterFrame()
  301.    {
  302.       this.gotoAndStop(this.sFrame);
  303.    }
  304. }
  305.